﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using TFXK.BLL;
using System.Data;
using TFXK.Common;

public partial class Message : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly MessageBLL bll = new MessageBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) { }
    }


    #region 分页绑定
    private void InitData(int PageIndex)
    {
        int count = 0;
        DataSet ds = new DataSet();
        ds = bll.GetWebList(AspNetPager1.PageSize, PageIndex, out count);
        AspNetPager1.RecordCount = count;

        this.rptContentMsg.DataSource = ds.Tables[0].DefaultView;
        this.rptContentMsg.DataBind();
    }
    #endregion

    #region 分页控件加载
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {

                InitData(e.NewPageIndex);
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }
    }
    #endregion
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string uname = StringUtil.HtmlEncode(txtUName.Value);
        string uemail = StringUtil.HtmlEncode(txtEmail.Value);
        string content = StringUtil.HtmlEncode(txtContent.Value);
        string uphone = StringUtil.HtmlEncode(txtTel.Value);
        if (string.IsNullOrEmpty(uname) || string.IsNullOrEmpty(content)) {
            Msg.Show("填写不完整！");
            return;
        }
        TFXK.Model.Message model = new TFXK.Model.Message();
        model.name = uname;
        model.parentId = 0;
        model.reply = "";
        model.state = "0";
        model.title = "";
        model.telephone = uphone;
        model.email = uemail;
        model.userId = 0;
        model.description = content;
        model.createTime = DateTime.Now+"";
        try
        {
            bll.Add(model);
            Msg.ShowAndRedirect("提交成功!","Message.aspx");
        }
        catch(Exception ex) {
            Msg.Show("留言失败！"+ex.Message);
        }
    }
}
